<?php
	class ToolbarsHelper extends HtmlxHelper
	{		
		/**
		 * CSS class for the toolbar table
		 */
		public $toolbarTableCssClass = 'toolbar';

		/**
		 * CSS class for the informational toolbar table
		 */
		public $infoToolbarTableCssClass = 'eva';

		/**
		 * CSS class for the info table label
		 */
		public $infoLabelSpanCssClass = 'infoLabel';
		
		/**
		 * CSS class for the info table value
		 */
		public $infoValueSpanCssClass = 'infoValue';
		
		/**
		 * CSS class for the empty div
		 */
		public $emptyDivCssClass = 'empty';
		
		/**
		 * CSS class for the toolbar button cell
		 */
		public $toolButtonCellCssClass = 'menubuttons';

		/**
		 * CSS class for the toolbar button link
		 */
		public $toolButtonLinkCssClass = 'menubuttons';

		/**
		 * Toolbar separator image name
		 */
		public $toolbarSeparatorImageName = 'toolbar_separator.gif';

		/**
		 * Toolbar background image name
		 */
		public $toolbarBackgroundImageName = 'toolbar_bg.gif';

		
		/**
		 * Generates toolbar with specified buttons
		 *
		 * @param array $buttons array of buttons. Example: $buttons = array('add_button' => array('image'=>'image.gif', 'text'=>'caption', 'url'=>'url_here'));
		 * @param string $width width of toolbar, default 100%
		 */	
		public function Toolbar($buttons, $width = '100%', $use_help = 0, $caption = '')
		{
		    //buttons parsing
		    foreach ($buttons as &$button)
		    {
		        $button['image'] = (empty($button['image'])) ? '' : IMAGES.$button['image'];
		    }
		    
		    //jQuery toolbar
            jQuery::Toolbar('toolbar_container', $buttons);

//			//displays toolbar caption if necessary
//			if ($caption != '')
//			{
//				echo "<table cellspacing = '0' cellpadding = '0' class = 'toolbarCaption'><tr><td class = 'toolbarCaption'>$caption</td></tr></table>";
//			}
//			
//			echo "<table class='$this->toolbarTableCssClass' cellspacing = '0' cellpadding = '0' border='0' width='".$width."'><tr><td>";
//
//			echo "<table cellspacing = '0' cellpadding = '0' border='0' ><tr><td width = 10>&nbsp&nbsp</td>";
//			$i=0;
//			foreach ($buttons as $key=>$value)
//			{
//				if ($i > 0)
//				{
//					$this->ToolButtonSeparator();
//				}
//				$this->ToolButton($value[image], $value[text], $value[url], $value[attributes]);
//				$i++;
//			}
//			
//			
//			echo "</tr></table>";
//				
//			echo "</td></tr></table>";
//			echo "<div class = '$this->emptyDivCssClass' style = 'height: 3px;'></div>";
		}
		
		/**
		 * DEPRICATED: Generates toolbar button
		 *
		 * @param string $image button image name (without path)
		 * @param string $text text on the button
		 * @param string $url button url
		 * @param string $attributes button (link) html attributes
		 * @param string $td_attributes button (cell) html attributes
		 */
		private function ToolButton($image, $text, $url, $attributes, $td_attributes = null)
		{
			global $current_controller;
			echo "<td class = '$this->toolButtonCellCssClass' $td_attributes>";
			if ((!isset($url))&&(empty($url)))
				echo "<a onmouseover='this.style.cursor=\"pointer\"' $attributes class = '$this->toolButtonLinkCssClass' style = 'background-image: url(/./app/themes/".$current_controller->theme."/images/".$image.");background-repeat: no-repeat; background-position:left top;'>$text</a>";
			else echo $this->link($url, $text, "$attributes class = '$this->toolButtonLinkCssClass' style = 'background-image: url(/./app/themes/".$current_controller->theme."/images/".$image.");background-repeat: no-repeat; background-position:left top;'");
			echo "</td>";
		}
		
		/**
		 * DEPRICATED: Generates tool button separator
		 *
		 */
		private function ToolButtonSeparator()
		{
			echo "<td align = 'center' width = '5px'>";
			echo $this->img("$this->toolbarSeparatorImageName", 1, 17);
			echo "</td>";
		}
		
		/**
		 * DEPRICATED: Generates tool bar separator
		 *
		 */
		private function ToolBarSeparator()
		{
			echo "<td align = 'left' width ='5'>";
			echo $this->img("$this->toolbarBackgroundImageName", 7, 20);
			echo "</td>";
		}

		/**
		 * Generates informational toolbar from an array
		 *
		 * @param array $value_array multidemensial array with [label] and [value] elements
		 */	
		public function ToolbarInfo(array $value_array)
		{
			echo '<table class="'.$this->infoToolbarTableCssClass.'" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="padding: 5px 15px 5px 15px">';
			foreach ($value_array as $value)
			{
				echo "<span class='$this->infoLabelSpanCssClass'>".ucfirst($value[label])."</span> - ";
				echo "<span class='$this->infoValueSpanCssClass'>".$value[value].'</span> | ';
			}
			echo '</td></tr></tbody></table>';
		}
	}
?>